#
# Copyright 2023 The Kumo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################
# system pthread and rt, dl
############################################################
set(KMCMAKE_SYSTEM_DYLINK)
if (APPLE)
    find_library(CoreFoundation CoreFoundation)
    list(APPEND KMCMAKE_SYSTEM_DYLINK ${CoreFoundation} pthread)
elseif (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
    list(APPEND KMCMAKE_SYSTEM_DYLINK rt dl pthread)
endif ()

if (KMCMAKE_BUILD_TEST)
    enable_testing()
    #include(require_gtest)
    #include(require_gmock)
    #include(require_doctest)
endif (KMCMAKE_BUILD_TEST)

if (KMCMAKE_BUILD_BENCHMARK)
    #include(require_benchmark)
endif ()

find_package(Threads REQUIRED)
find_package(turbo REQUIRED)
include_directories(${turbo_INCLUDE_DIR})
find_package(ZLIB REQUIRED)
find_package(zstd CONFIG REQUIRED)
find_package(Snappy REQUIRED)
find_package(BZip2 REQUIRED)
find_package(unofficial-brotli CONFIG REQUIRED)
find_package(lz4 CONFIG REQUIRED)

set(ENABLE_ZLIB TRUE)
set(ENABLE_LZ4 TRUE)
set(ENABLE_SNAPPY TRUE)
set(ENABLE_ZSTD TRUE)
set(ENABLE_BZIP2 TRUE)

message(STATUS "ENABLE_ZLIB: ${ENABLE_ZLIB}")
message(STATUS "ENABLE_LZ4: ${ENABLE_LZ4}")
message(STATUS "ENABLE_SNAPPY: ${ENABLE_SNAPPY}")
message(STATUS "ENABLE_ZSTD: ${ENABLE_ZSTD}")
message(STATUS "ENABLE_BZIP2: ${ENABLE_BZIP2}")

############################################################
#
# add you libs to the KMCMAKE_DEPS_LINK variable eg as turbo
# so you can and system pthread and rt, dl already add to
# KMCMAKE_SYSTEM_DYLINK, using it for fun.
##########################################################
set(KMCMAKE_DEPS_LINK
        #${TURBO_LIB}
        ZLIB::ZLIB
        zstd::libzstd
        Snappy::snappy
        BZip2::BZip2
        turbo::turbo_static
        lz4::lz4
        unofficial::brotli::brotlidec
        unofficial::brotli::brotlienc
        ${KMCMAKE_SYSTEM_DYLINK}
        )
list(REMOVE_DUPLICATES KMCMAKE_DEPS_LINK)
kmcmake_print_list_label("Denpendcies:" KMCMAKE_DEPS_LINK)





